package com.spr.gw.service.impl;

import com.spr.gw.common.ResponseCode;
import com.spr.gw.common.ResultBean;
import com.spr.gw.entity.Category;
import com.spr.gw.mapper.CategoryMapper;
import com.spr.gw.service.CategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by lsy
 * on 2017/10/25 16:19.
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Resource
    private CategoryMapper categoryMapper;

    @Override
    public ResultBean<List<Category>> getCategoryByType(String typeid) {
        List<Category> list = categoryMapper.selectChildCategory(Category.builder().type(typeid).build());
        if(list.size() > 0){
            return ResultBean.createBySuccess(list);
        }else{
            return ResultBean.createByCodeMessage(ResponseCode.NO_RESULT.getCode(),ResponseCode.NO_RESULT.getDesc());
        }
    }

    @Override
    public List<Category> findChildCategoryByPid(Integer i) {
        List<Category> categories = categoryMapper.selectChildCategory(Category.builder().pid(i).build());
        return categories;
    }

    @Override
    public Category findCategoryByPrimaryKey(Integer id) {
        return categoryMapper.selectByPrimaryKey(id);
    }
}
